package com.lqr.wechat.activity;

import android.content.Intent;
import android.view.MenuItem;
import android.view.View;

import com.bridge.imconfig.IMApplication;
import com.bridge.imconfig.NimAccountSDK;
import com.bridge.imconfig.view.CustomDialog;
import com.lqr.wechat.R;
import com.lqr.wechat.databinding.ActivitySettingBinding;

/**
 * @创建者 CSDN_LQR
 * @描述 设置界面
 */
public class SettingActivity extends BaseActivity {

    Intent intent;
    private View mExitDialogView;
    private CustomDialog mDialog;
    private ActivitySettingBinding binding ;

    @Override
    protected int layoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initView() {
        binding = getBind() ;
        initToolbar();
    }

    @Override
    public void initListener() {
        binding.oivDontDistorbSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, DontDistorbSetActivity.class);
                startActivity(intent);
            }
        });
        binding.oivCheatSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, CheatSetActivity.class);
                startActivity(intent);
            }
        });
        binding.oivPrivacySet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, PrivacySetActivity.class);
                startActivity(intent);
            }
        });
        binding.oivCommon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, CommonSetActivity.class);
                startActivity(intent);
            }
        });
        binding.oivAccountAndSafeSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, AccountAndSafeSetActivity.class);
                startActivity(intent);
            }
        });
        binding.oivAbout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, AboutActivity.class);
                startActivity(intent);
            }
        });
        binding.oivExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mExitDialogView == null) {
                    mExitDialogView = View.inflate(SettingActivity.this, R.layout.dialog_exit, null);
                    mDialog = new CustomDialog(SettingActivity.this, mExitDialogView, R.style.dialog);
                    mDialog.show();

                    mExitDialogView.findViewById(R.id.tvExitAccount).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //退出当前账号
                            NimAccountSDK.logout();
                            intent = new Intent(SettingActivity.this, LoginActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                            mDialog.dismiss();
                        }
                    });

                    mExitDialogView.findViewById(R.id.tvExitApp).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //退出app
                            IMApplication.exit();
                            mDialog.dismiss();
                        }
                    });

                } else {
                    mDialog.show();
                }
            }
        });
        binding.oivNewMsgNotifySet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(SettingActivity.this, NewMsgNotifySetActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void initToolbar() {
        setSupportActionBar(binding.lyToolbar.toolbar);
        getSupportActionBar().setTitle("设置");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        binding.lyToolbar.toolbar.setNavigationIcon(R.mipmap.ic_back);
    }
}
